import os
folder_path = '.'
file_names = os.listdir(folder_path)

min_length = min(len(name) for name in file_names)
common_strings = []
for i in range(min_length):
    current_char = file_names[0][i]
    if all(name[i] == current_char for name in file_names):
        common_strings.append(current_char)
    else:
        break

common_string = ''.join(common_strings)
print(f"提取到的相同字符串为：{common_string}")

for filename in file_names:
    # 检查文件是否包含要删除的字符串
    if common_string in filename:
        # 构造完整的文件路径
        old_file_path = os.path.join(folder_path, filename)
        # 删除文件名中的特定字符串
        new_filename = filename.replace(common_string, '')
        # 构造新的文件路径
        new_file_path = os.path.join(folder_path, new_filename)
        # 重命名文件
        os.rename(old_file_path, new_file_path)
        print(f'Renamed "{old_file_path}" to "{new_file_path}"')
